package com.zr.share.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @ClassName SwaggerConfig
 * @Description TODO
 * @Author Jiakui_Ma
 * @Date 2019/11/17 11:14
 */
@Configuration //加载到配置文件
@EnableSwagger2 //开启swagger
public class SwaggerConfig {
    //配置了swagger 的Docket bean实例
    @Bean
    public Docket docket(Environment environment){
        //设置要显示的swagger坏境
        Profiles profiles = Profiles.of("dev","test");
        //判断是否处在在自己设定的环境中
        boolean flag = environment.acceptsProfiles(profiles);
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("马家奎")
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zr.inquiry"))
                .build();
    }

    private ApiInfo apiInfo() {

        Contact contact = new Contact("马家奎","fsfg" ,"jkui_dlnu@163.com");

        ApiInfo apiInfo = new ApiInfo("询价清单项目", "API文档自动生成", "1.0", "urn:tos", contact, "MIT", "https://mit-license.org/", new ArrayList());

        return apiInfo;
    }

}
